import java.sql.*;

public class TestBatch {
	public static void main(String[] args) {
		/*
		Statement stat = null;
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:lovemanai", "scott", "tiger");
			
			stat = conn.createStatement();
			stat.addBatch("insert into dept2 values (51, 'QAQ', '233')");
			stat.addBatch("insert into dept2 values (52, 'QAQ', '233')");
			stat.addBatch("insert into dept2 values (53, 'QAQ', '233')");
			
			stat.executeBatch();
			
			
		} catch (ClassNotFoundException e) {
			System.out.println("没有找到相应驱动");
		} catch(SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if(stat != null) {
					stat.close();
					stat = null;
				}
			} catch(SQLException e) {
				e.printStackTrace();
			}
			
		}
		*/
		PreparedStatement pStat = null;
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:lovemanai", "scott", "tiger");
			
			pStat = conn.prepareStatement("insert into dept2 values(?, ?, ?)");
			pStat.setInt(1, 23);
			pStat.setString(2, "QAQ");
			pStat.setString(3, "QAQ");
			pStat.addBatch();
			
			
			pStat.setInt(1, 24);
			pStat.setString(2, "QAQ");
			pStat.setString(3, "QAQ");
			pStat.addBatch();
			
			
			pStat.setInt(1, 25);
			pStat.setString(2, "QAQ");
			pStat.setString(3, "QAQ");
			pStat.addBatch();
			
			pStat.executeBatch();
			
		} catch(ClassNotFoundException e) {
			System.out.println("没有找到相应驱动");
		} catch(SQLException e) {
			e.printStackTrace();
		} finally {
			try{
				if(pStat != null) {
					pStat.close();
					pStat = null;
				}
			} catch(SQLException e) {
				e.printStackTrace();
			}
			
		}
		
	}
}
